import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/common/role_menu_tree_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/apply_bean.dart';
import 'package:enterprise_v6_app/app/modules/application/controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

class DoublePreventionController extends GetxController {
  /// 首页controller
  final applyController = Get.find<ApplyController>();

  /// 应用路由名称与子类菜单名称对应关系
  Map<String, List<RoleMenuTreeEntity>> roleMenuMap = {};

  /// 后台与左侧标签的对应关系
  Map<String, ApplyBean> moduleMap = {
    '/riskControl': ApplyBean(
      '风险管控',
      Colors.white,
      AppImages.icon_risk_control,
      routes: AppRoutes.riskControl,
    ),
    '/hiddenDiseaseSearch': ApplyBean(
      '隐患排查',
      Colors.white,
      AppImages.icon_hazard_investigation,
      routes: AppRoutes.hiddenDiseaseSearch,
    ),
  };
  final List<ApplyBean> doublePreventionList = [];

  @override
  void onInit() {
    super.onInit();
    initModule();
  }

  /// 根据后台权限初始化菜单
  void initModule() {
    final roleMenuList = applyController.roleMenuMap[AppRoutes.doublePrevention];
    if (roleMenuList != null) {
      for (var item in roleMenuList) {
        // 添加对应关系
        roleMenuMap[item.path!] = item.children!;
        // 添加模块
        final module = moduleMap[item.path];
        if (module != null) {
          doublePreventionList.add(module);
        }
      }
    }
    update();
  }

  /// 台账操作列表
  final List<ApplyBean> doublePreventionListO = [
    ApplyBean(
      '风险管控',
      Colors.white,
      AppImages.icon_risk_control,
      routes: AppRoutes.riskControl,
    ),
    ApplyBean(
      '隐患排查',
      Colors.white,
      AppImages.icon_hazard_investigation,
      routes: AppRoutes.hiddenDiseaseSearch,
    ),
  ];
}
